// BmpImage.cpp: implementation of the BmpImage class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "BmpImage.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

IMPLEMENT_DYNAMIC(BmpImage, Image)

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

BmpImage::BmpImage()
{
	construct(CString());
}

BmpImage::BmpImage(LPTSTR file)
	: Image(file)
{
	construct(CString(file));
}

BmpImage::BmpImage(CString& file)
	: Image(file)
{
	construct(file);
}

BmpImage::~BmpImage()
{
	if (m_hbmp != NULL)
		::BmpDestroy(m_hbmp);
}

BOOL BmpImage::loadImage()
{
	if (m_hbmp != NULL)
	{
		::BmpDestroy(m_hbmp);
		m_hbmp = NULL;
	}
	if (!m_file.IsEmpty())
		m_hbmp = ::BmpCreate(m_file.GetBuffer(0));
	return (m_hbmp != NULL);
}

void BmpImage::paint(CDC* pDC, AWTCanvas* canvas)
{
	if (m_hbmp != NULL)
	{
		HBRUSH hbr = (HBRUSH)::GetStockObject(NULL_BRUSH);
		RECT rc;
		canvas->getPeer()->GetClientRect(&rc);
		BmpPaint(m_hbmp, pDC->m_hDC, rc, FALSE, hbr); 
	}	
}

CSize BmpImage::getSize()
{
	if (m_hbmp == NULL)
		return CSize(0,0);
	CSize sz;
	::BmpGetSize(m_hbmp, &sz);
	return sz;
}
